package com.example.rabbitmq.example.rabbitmq.route;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.nio.charset.StandardCharsets;
import java.util.Random;

public class RouteProceducer {

    private static String[] LEVEL = {"ERROR", "INFO", "WARN"};
    private static Random random = new Random();
    public static void main(String[] args) throws Exception{

        ConnectionFactory factory = new  ConnectionFactory();
        factory.setUri("amqp://admin:admin@192.168.1.3:5672/%2f");
        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();

        channel.exchangeDeclare("exchange_route", "direct",false,false, null);

        for (int i = 0; i < 100; i++) {
            String level = LEVEL[random.nextInt(100)%LEVEL.length];
            channel.basicPublish("exchange_route", level, null, ("这是"+level).getBytes(StandardCharsets.UTF_8));
        }
        channel.close();
        connection.close();
    }
}
